package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-04-25 21:07
 */
public class QLint604 {
    public int[] winSum(int[] nums, int k) {
        if(nums == null || nums.length == 0) {
            return null;
        }

        int[] res = new int[nums.length - k + 1];
        int i = 0, j = k - 1;

        int sum = 0;
        for (int l = 0; l < k; l++) {
            sum += nums[l];
        }
        res[0] = sum;

        while (j < nums.length - 1) {
            sum -= nums[i];
            i++;
            j++;
            sum += nums[j];
            res[i] = sum;
        }

        return res;
    }
}
